<template>
  <div id="App">
    <form action="">
      姓名:<input type="text" v-model="name" /><br />
      年龄:<input type="text" v-model="age" /><br />
      身高:<input type="text" v-model.number="height" />(米) <br />
      体重:<input type="text" v-model.number="weight" />(公斤) <br />
      病史:<input type="text" v-model="illHistory" /><br />
      <button @click="fn()">诊断</button>
    </form>
  </div>
</template>
<script>
export default {
  name: 'App',
  data () {
    return {
      name: '',
      age: '',
      height: '',
      weight: '',
      illHistory: ''
    }
  },
  created () {
  },
  computed: {
  },
  methods: {
    fn () {
      if (this.name && this.age && this.height && this.weight && this.illHistory) {
        const BMI = this.weight / (this.height ^ 2)
        console.log(BMI)
        if (BMI <= 18.5) {
          alert('体重过轻')
        } else if (BMI < 18.5 && BMI <= 24.9) {
          alert('正常')
        } else if (BMI < 24.9 && BMI <= 29.9) {
          alert('体重过重')
        } else if (BMI > 29.9) {
          alert('肥胖')
        }
        this.name = this.age = this.height = this.weight = this.illHistory = ''
      } else {
        alert('请输入完整信息')
      }
    }
  }
}
</script>
<style lang='less'  scoped>
</style>
